package com.itheima.youdianda.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.youdianda.domain.SysMenu;
import com.itheima.youdianda.domain.SysRoleMenu;
import com.itheima.youdianda.service.SysMenuService;
import com.itheima.youdianda.service.SysRoleMenuService;
import com.itheima.youdianda.mapper.SysRoleMenuMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
* @author YUAN
* @description 针对表【sys_role_menu(角色-菜单)】的数据库操作Service实现
* @createDate 2022-09-06 18:36:38
*/
@Service
public class SysRoleMenuServiceImpl extends ServiceImpl<SysRoleMenuMapper, SysRoleMenu>
    implements SysRoleMenuService{

    @Autowired
    private SysMenuService menuService;

    @Override
    public List<SysMenu> getRoleMenu(List<String> roleIds) {
        LambdaQueryWrapper<SysRoleMenu> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(SysRoleMenu::getRoleId, roleIds);
        Set<String> menuIds = baseMapper.selectList(queryWrapper).stream().map(SysRoleMenu::getMenuId).collect(Collectors.toSet());
        LambdaQueryWrapper<SysMenu> queryWrapper2 = new LambdaQueryWrapper<>();
        queryWrapper2.in(SysMenu::getId, menuIds);
        List<SysMenu> menuList = menuService.list(queryWrapper2);
        return menuList;
    }

    @Override
    public void add(Integer id, String[] roleIds) {
        baseMapper.add(id, roleIds);
    }

    @Override
    public void addRoleMenus(String id, List<String> menuids) {
        baseMapper.addRoleMenus(id, menuids);
    }
}




